<?php
require_once DIR_APPLICATION . 'controller/abstract.php';

class ControllerStoryHome extends AppController {

      public function index() {
            $this->load->model('story/category');
            $this->load->model('story/content');

            $rows = [];
            $categories = $this->model_story_category->list();
            foreach ($categories as $category) {
                  $categoryId = (int)$category['category_id'];
                  $rows[] = [
                        'title' => $category['name'],
                        'rows' => $this->model_story_content->top($categoryId)
                  ];
            }

            $this->jsonSuccess($rows);
      }
}